<?php
/**
 * Created by IntelliJ IDEA
 * Author: 张伯发
 * Date  : 2019/11/19
 * Time  : 17:17
 */

namespace Xiaoproject\Common\Language;

/**
 * 国际化处理
 * 对前端传递过来的language，进行处理
 * Class LanguageBuilder
 * @author 张伯发 2019/11/19 17:33
 */
class LanguageBuilder
{
    /**
     * @param string $key
     * @param array $params
     * @param string $locale
     * @return string
     * @author 张伯发 2019/11/19 17:23
     */
    public function get(string $key, array $params = [], string $locale = '') : string
    {
        if (empty($locale)) {
            $locale = context()->getRequest()->input('language');
            if (!in_array($locale, ['zh', 'en'])) $locale = '';
        }
        return \Swoft::t($key, $params, $locale);
    }
}
